#ifndef WXSITEMEDITOR_H
#define WXSITEMEDITOR_H

#include "wxsitemres.h"
#include "../wxseditor.h"

#include <wx/hashset.h>
#include <wx/notebook.h>
#include <wx/bmpbuttn.h>
#include <wx/sizer.h>
#include <wx/scrolwin.h>

class wxsItemEditorContent;
class wxsItemResData;
class wxsToolSpace;
class wxsItemInfo;
class wxsItem;


class wxsItemEditor : public wxsEditor {
  public:


    wxsItemEditor( wxWindow* parent, wxsItemRes* ItemRes );


    virtual ~wxsItemEditor();


    virtual bool Save();


    static void ConfigChanged();

  protected:


    virtual bool GetModified() const;


    virtual bool CanUndo() const;


    virtual bool CanRedo() const;


    virtual bool HasSelection() const;


    virtual bool CanPaste() const;


    virtual bool IsReadOnly() const;


    virtual void Undo();


    virtual void Redo();


    virtual void Cut();


    virtual void Copy();


    virtual void Paste();

  private:

    WX_DECLARE_HASH_SET( wxsItemEditor*, wxPointerHash, wxPointerEqual, WindowSet );


    void OnMouseClick( wxMouseEvent& event );
    void OnButton( wxCommandEvent& event );
    void OnInsPoint( wxCommandEvent& event );
    void OnInsInto( wxCommandEvent& event );
    void OnInsBefore( wxCommandEvent& event );
    void OnInsAfter( wxCommandEvent& event );
    void OnDelete( wxCommandEvent& event );
    void OnPreview( wxCommandEvent& event );
    void OnQuickProps( wxCommandEvent& event );
    void OnKeyDown( wxKeyEvent& event );
    void OnPopup( wxCommandEvent& event );

    void InitializeVisualStuff();
    void InitializeResourceData();


    static void InitializeImages();


    void BuildPalette( wxNotebook* Palette );

    inline wxsItemRes* GetItemRes() { return ( wxsItemRes* )GetResource(); }
    inline const wxString& GetWxsFileName() { return GetItemRes()->GetWxsFileName(); }
    inline const wxString& GetSrcFileName() { return GetItemRes()->GetSrcFileName(); }
    inline const wxString& GetHdrFileName() { return GetItemRes()->GetHdrFileName(); }
    inline const wxString& GetXrcFileName() { return GetItemRes()->GetXrcFileName(); }


    void InsertRequest( const wxString& Name );


    void SetInsertionTypeMask( int Mask );


    void SetInsertionType( int Type );


    void RebuildInsTypeIcons();


    void RebuildQuickPropsIcon();


    void RebuildIcons();


    void BuildInsTypeIcon( wxBitmapButton* Btn, const wxImage& Original, int ButtonType );


    void ToggleQuickPropsPanel( bool Open );


    void RebuildQuickProps( wxsItem* Selection );


    void RebuildPreview();


    void UpdateSelection();


    void UpdateModified();


    wxsItem* GetReferenceItem( int& InsertionType );


    void StartInsertPointSequence( const wxsItemInfo* Info );


    static void ReloadImages();


    static void RefreshContents();


    void ShowPopup( wxsItem* Item, wxMenu* Menu );

    wxsItemResData* m_Data;
    wxsItemEditorContent* m_Content;    ///< \brief Window with content area
    wxsToolSpace* m_ToolSpace;          ///< \brief Space for tools in resource
    wxNotebook* m_WidgetsSet;           ///< \brief Notebook with all widgets inside
    wxBoxSizer* m_VertSizer;            ///< \brief Root sizer of this editor
    wxBoxSizer* m_HorizSizer;           ///< \brief Horizontal sizer managing items below palette
    wxBoxSizer* m_QPSizer;              ///< \brief Sizer for quick properties
    wxBoxSizer* m_OpsSizer;             ///< \brief Sizer for operations pane
    wxScrolledWindow* m_QPArea;         ///< \brief Scrolled window containing all QuickProps sturr
    wxBitmapButton* m_InsPointBtn;
    wxBitmapButton* m_InsIntoBtn;
    wxBitmapButton* m_InsBeforeBtn;
    wxBitmapButton* m_InsAfterBtn;
    wxBitmapButton* m_DelBtn;
    wxBitmapButton* m_PreviewBtn;
    wxBitmapButton* m_QuickPanelBtn;
    wxWindow* m_TopPreview;             ///< \brief Top window of preview
    wxPanel* m_PreviewBackground;       ///< \brief Background panel used as background for preview
    int m_InsType;                      ///< \brief Current insertion type
    int m_InsTypeMask;                  ///< \brief Current insertion type mask
    bool m_QuickPropsOpen;              ///< \brief Set to true if quick properties panel is opened
    wxsItem* m_PopupCaller;
    static wxImage m_InsPointImg;
    static wxImage m_InsIntoImg;
    static wxImage m_InsBeforeImg;
    static wxImage m_InsAfterImg;
    static wxImage m_DelImg;
    static wxImage m_PreviewImg;
    static wxImage m_QuickPropsImgOpen;
    static wxImage m_QuickPropsImgClose;
    static wxImage m_SelectedImg;
    static WindowSet m_AllEditors;
    static bool m_ImagesLoaded;

    static const int itPoint  = 0x01;
    static const int itBefore = 0x02;
    static const int itAfter  = 0x04;
    static const int itInto   = 0x08;

    DECLARE_EVENT_TABLE()

    friend class wxsItemEditorContent;
    friend class wxsItemResData;
    friend class wxsItem;
};

#endif
